<?php
/**
 * PHP versions 4 and 5
 * Magic
 * Licensed under The Open Group Test Suite License
 * Redistributions of files must retain the above copyright notice.
 * @copyright     Copyright 2011
 * @link
 * @package       Magic Lib
 * @since         MaginPHP 1.0
 * @license
 */
?>
<?php

/**
 * @desc : This is the base controller class must inherit by all the controller class . 
 */
abstract class base_controller {
    /**
     * @desc : This is magic upload class object
     */
    public $upload ; 
    /**
     * @desc : This is the collection of data set 
     * This variable is dynamic variable .
     * Use to collect the information regarding view parameter .
     * The prameters define in the controller via $this operation are 
     * store into this data array .
     * After that we can det that data array value from $view object .
     * 
     */
    public $data = array ();
    /**
     * 
     * @var type 
     */
    protected  $class;
    /**
     * @desc : This variable catch the value of action class
     * This is the dynamic variable .
     * Value is change on every http request .
     * @var type : protected  
     */
    protected $action  ;
    /**
     * @desc : store the file extention 
     * @var type 
     */
    protected $exception ; 
    /**
     * @desc : php magic methoad set 
     */
    public function __set($name, $value) {
        $this->data[$name] = $value;
    }
    /**
     * @desc : php magic methoad
     */
    public function __get($name) {
        return $this->data[$name];
    }
    /**
     * @desc : This is contructor of the base class 
     * Every child controller class inherit this contructor . 
     * @param type $class : name of class which you want to upload dynamically 
     * @param type $session : if you allow the session the value yes / or no 
     * @param type $sessionPara : array of session parameters 
     * @param type $redirectPara : array of redirect parameters 
     */
    public function __construct($class,$session = false ,$sessionPara = NULL, $redirectPara = array()) {
        $this->action = Magic::callMethod()->getViewAction();
        if($session == true) {
            if(key_exists("exception",$redirectPara) && !empty($redirectPara["exception"])) {
                if(is_array($redirectPara["exception"])){
                    if(!in_array($this->action, $redirectPara["exception"])){
                        if(Magic_Session_Lib::callMethod()->_getSession($sessionPara) == 'null') {
                          Magic_Common_Model::callMethod()->_pageRedirect(SITE_URL.$redirectPara["module"]."/".$redirectPara["controller"]."/".$redirectPara["action"]);
                        }
                    } 
                }
            } else {
                if(Magic_Session_Lib::callMethod()->_getSession($sessionPara) == 'null') {
                    Magic_Common_Model::callMethod()->_pageRedirect(SITE_URL.$redirectPara["module"].DS.$redirectPara["action"]);
                }
            }
        }
        $this->upload = new Magic_ClassUpload_Model;
        if(!empty($class)) {
            $this->upload->uploadClass(array($class));
        }
    }
    /**
     * @desc : This is the index controller must include by every child class  
     */
    abstract public function indexController();
 }
?>
